package com.kim.net.impl;

import com.kim.net.NetCallback;
import com.kim.net.NetEntity;

/**
 * 网络请求代理类
 * 
 * @author Kim
 * 
 */
public class NetProcessProxy {

	/**
	 * 网络请求类型
	 * 
	 * @author Kim
	 * 
	 */
	public enum NetRequestType {
		GET, POST;
	}

	public static final void proxy(NetEntity entity, NetCallback netCallback,
			NetRequestType type) {
		switch (type) {
		case GET:
			doGet(entity, netCallback);
			break;
		case POST:
			doPost(entity, netCallback);
		}
	}

	/**
	 * get请求
	 * 
	 * @param entity
	 * @param netCallback
	 */
	public static final void doGet(final NetEntity entity,
			final NetCallback netCallback) {
		new Thread(new Runnable() {
			@Override
			public void run() {
				new NetGetImpl(entity.url, netCallback).sendEntity();
			}
		}).start();
	}

	public static final void doGet(final String url,
			final NetCallback netCallback) {
		new Thread(new Runnable() {
			@Override
			public void run() {
				new NetGetImpl(url, netCallback).sendEntity();
			}
		}).start();
	}

	/**
	 * post请求
	 * 
	 * @param entity
	 * @param netCallback
	 */
	public static final void doPost(final NetEntity entity,
			final NetCallback netCallback) {
		new Thread(new Runnable() {
			@Override
			public void run() {
				new NetPostImp(entity, netCallback).sendEntity();
			}
		}).start();
	}

}
